/**
 * @see [微信官方](https://mp.weixin.qq.com/debug/wxadoc/dev/api/network-socket.html#wxclosesocket)
 * @param count [number] 最多可以选择的图片张数，默认9
 * @param sizeType [number] original 原图，compressed 压缩图，默认二者都有
 * @param sourceType [number] album 从相册选图，camera 使用相机，默认二者都有
 */
export default function choose_image(count?: number, sizeType?: 1 | 2 | 4, sourceType?: 1 | 2 | 4) {
	const size_type = ((s_type) => {
		switch (s_type) {
			case 1:
				return ['original'] as wx.ImageSizeType[];
			case 2:
				return ['compressed'] as wx.ImageSizeType[];
			case 4:
				return ['original', 'compressed'] as wx.ImageSizeType[];
			default:
				return ['original', 'compressed'] as wx.ImageSizeType[];
		}
	})(sizeType);
	const source_type = ((s_type) => {
		switch (s_type) {
			case 1:
				return ['album'] as wx.ImageSourceType[];
			case 2:
				return ['camera'] as wx.ImageSourceType[];
			case 4:
				return ['album', 'camera'] as wx.ImageSourceType[];
			default:
				return ['album', 'camera'] as wx.ImageSourceType[];
		}
	})(sourceType);
	return new Promise<{
		success: boolean;
		msg: wx.TempFilesData
	}>((resolve) => {
		wx.chooseImage({
			count, 						// 默认9
			sizeType: size_type, 		// 可以指定是原图还是压缩图，默认二者都有
			sourceType: source_type,	// 可以指定来源是相册还是相机，默认二者都有
			success(res) {				// 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
				resolve({
					msg: res,
					success: true
				});
			},
			fail(res) {
				resolve({
					msg: res,
					success: false
				});
			}
		});
	});
}
